/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package queenb.web.controller.project;

import java.util.*;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import queenb.net.entitybean.C150;
import queenb.net.entitybean.C300;
import queenb.net.entitybean.M650;
import queenb.web.controller.QueenbController;
import queenb.web.store.C150Store;
import queenb.web.store.C300Store;
import queenb.web.store.M650Store;
import queenb.web.util.Util;

/**
 *
 * @author VANANH
 */
public class C300Controller extends QueenbController {

    private List<SelectItem> listTime = new ArrayList<SelectItem>();
    private int PC300;
    private int CN307 = 15;
    private Date CD301 = new Date();
    private Date CD302 = new Date();
    private String CB317;
    private int CN315 = 0;
    private String FC150;
    private int pnFC150;
    private C300Store c300Store;
    private M650Store m650Store;
    private List<C150> listc150;
    private C150Store c150Store;
    private int FN600;
    private String CV151;// Tên công việc 
    private String CB173;// Mô tả
    private int FB050;// Dự án
    private String FC550;// Loại Coongv iệc
    private int FC500 = 1;// Trạng thái
    private int FS200; //Chuyên môn
    private Date CD152;// Ngày bắt đầu
    private Date CD153;// Ngày kết thúc
    private int FS250;// Chuyên môn công việc
    private String CV165;// Tên login khi nhân viên đang nhập 
    private int FC450 = 2;// Độ ưu tiên của dự án
    private String CL196;
    private Date cd196;
    private String emp_login;
    private String nameproject;
    private C150 c150;
    private String emp;
    private String messagefrom;
    private int fis = 0;

    public C300Controller() {
        c300Store = new C300Store();
        c150Store = new C150Store();
        try {
            Object objAction = getRequest().getParameter("action");
            System.out.println("---objAction+++++++++++++" + objAction);
            Object fn600Object = getRequest().getParameter("FN600");
            if (fn600Object != null) {
                FN600 = Integer.parseInt(fn600Object.toString());
            }
            Object objEmp = getRequest().getParameter("emp");
            Object objFis = getRequest().getParameter("fis");
            Object objCn315 = getRequest().getParameter("CN315");
            if (objCn315 != null) {
                CN315 = Integer.parseInt(objCn315.toString());
            }
            if (objFis != null) {
                fis = Integer.parseInt(objFis.toString());
            } else {
                fis = 0;
            }
            if (getRequest().getParameter("action") != null && objFis != null) {
                System.out.println("---C300Controller+++++++++++fis++" + fis);
                String action = getRequest().getParameter("action").toString();

                if (action.equals("edit")) {

                    if (fn600Object != null && objEmp != null) {
                        System.out.println("action---edit 2");
                        this.FN600 = Util.parseInt(fn600Object);
                        this.emp = objEmp.toString();
                        fis = Integer.parseInt(objFis.toString());
                        getC150FByID(FN600, emp, fis);
                    }
                }
            }

            Object fc150 = getRequest().getParameter("FC150");
            if (fc150 != null) {
                FC150 = fc150.toString();
                System.out.println("---FC150+++++++++++++" + FC150);
            }
            Object objFC500 = getRequest().getParameter("FC500");
            if (fc150 != null) {
                FC500 = Integer.parseInt(objFC500.toString());
                System.out.println("---FC500+++++++++++++" + FC500);
            }

            System.out.println("---C300Controller+++++++++++fis++" + fis);
            if (objEmp != null) {
                emp = objEmp.toString();
            } else {
                emp = getLogin().getUserName();
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }



    }

    private void getC150FByID(int FN600, String emp, int days) {
        try {
            List<C150> listc150 = null;
            if (days == 0) {
                listc150 = c150Store.listC150All(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, null, "P", Util.toSQLDate(new Date()), 0, 0, emp, getLogin().getStatus(), 0, 2, 0, 1, getLogin().getUserName());

            } else if (days == 2) {
                listc150 = c150Store.listC150CR(getLogin().getModule(), getLogin().getCompanyNo(), 0, 0, null, "P", Util.toSQLDate(new Date()), 0, 0, emp, getLogin().getStatus(), 0, 2, 0, 1, getLogin().getUserName());

            } else {
                listc150 = c150Store.listC150F(getLogin().getModule(), getLogin().getCompanyNo(), 0, getLogin().getStatus(), emp, days, 0, 2, 0, 0, getLogin().getUserName());
            }

            if (listc150 != null && listc150.size() > 0) {
                for (int i = 0; i < listc150.size(); i++) {
                    if (listc150.get(i).getFn600() == FN600) {
                        this.FC150 = listc150.get(i).getPc150();
                        this.CV151 = listc150.get(i).getCv151();
                        this.nameproject = listc150.get(i).getSv201();
                        this.FC450 = listc150.get(i).getFc450();
                        this.FC500 = listc150.get(i).getFc500();
                        this.CV165 = listc150.get(i).getLogin();
                        this.CD152 = listc150.get(i).getCd152();
                        this.CD153 = listc150.get(i).getCd153();
                        this.CB173 = listc150.get(i).getCb173();
                        this.FS200 = listc150.get(i).getFs200();
                        this.emp_login = listc150.get(i).getCv165();
                        this.FS250 = listc150.get(i).getCn169();
                        this.FN600 = listc150.get(i).getFn600();
                        this.FB050 = listc150.get(i).getCn168int();
                        this.FC550 = listc150.get(i).getFc550();
                        this.CL196 = listc150.get(i).getCl196();
                        this.cd196 = listc150.get(i).getCd196();

                        this.CN315 = Integer.parseInt(listc150.get(i).getCv613());
                    }
                }
            }
        } catch (Exception ex) {
            System.out.println("Error. ERROR CODE: " + ex.getMessage());
        }
    }
    public void change(ActionEvent ac) {

        System.out.println("---change groupppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp" + CN307);
        checkTime();

    }

    public void reload() {
        System.out.println("---change+++++++++++++");
    }

    public List<C300> getListC300ByID() {
        try {
            System.out.println("---getListC300ByID+++++++++++++" + FC150 + "---" + PC300);
            List<C300> listC300 = c300Store.listC300(FC150, PC300);
            System.out.println("---getListC300ByID+++++++++++++" + listC300.size());
            return listC300;

        } catch (Exception ex) {
            System.out.println("----------------------------------------" + ex.getMessage());
            return null;
        }
    }

    public List<M650> getListDocumentC150() {
        m650Store = new M650Store();
        try {
            List<M650> listM650 = m650Store.findM650(getLogin().getModule(), getLogin().getCompanyNo(), 0, FC150, 0, 0, 0, null, "C150", 0, 0, null, null,0,10000,0,0, getLogin().getUserName());
            // List<M650> listM650 = m650Store.findM650(getLogin().getModule(), getLogin().getCompanyNo(), 0, null, 0, 0, 0, null, 'C150', 0, FC150, null, null, getLogin().getUserName());
            return listM650;
        } catch (Exception e) {
            return null;
        }
    }

    public List<M650> getListDocumentC300() {
        m650Store = new M650Store();
        try {
            List<M650> listM650 = m650Store.findM650(getLogin().getModule(), getLogin().getCompanyNo(), 0, FC150, 0, 0, 0, null, "C300", 0, 0, null, null,0,10000,0,0, getLogin().getUserName());
            // List<M650> listM650 = m650Store.findM650(getLogin().getModule(), getLogin().getCompanyNo(), 0, null, 0, 0, 0, null, 'C150', 0, FC150, null, null, getLogin().getUserName());
            return listM650;
        } catch (Exception e) {
            return null;
        }
    }

    public void save() {
        try {
            int count = 0;
            System.out.println("----FC150---" + getFC150() + "----FN100---" + getLogin().getId() + "----FC500---" + FC500 + "----CD301----" + CD301 + "---CD302---" + CD302 + "----CN307---" + CN307 + "---CN315---" + CN315 + "----CB317----" + CB317);
            count = c300Store.updateC300(getLogin().getModule(), FC150, PC300, FC500, getLogin().getId(), 0, 0, Util.toSQLDate(CD301), Util.toSQLDate(CD302), null, null, null, null, CN307, null, 0, 0, null, null, null, null, CN315, 0, CB317, getLogin().getUserName());
            System.out.println("rs --------------------------------:" + count);
            if (count > 0) {
                setMessagefrom(getResourceString("success"));
            } else {
                setMessagefrom(getResourceString("error"));
            }
        } catch (Exception ex) {

            System.out.println("----------------------------------------" + ex.getMessage());

        }

    }

    public void checkTime() {
        Calendar now = Calendar.getInstance();
        now.add(Calendar.MINUTE, -CN307);
        CD301 = now.getTime();

    }

    /**
     * @return the listTime
     */
    public List<SelectItem> getListTime() {
        for (int i = 1; i < 32; i++) {
            String s = "";
            if (i * 15 >= 60) {
                s += (i * 15) / 60 + " Giờ ";
            }
            if ((i * 15) % 60 > 0) {
                s += (i * 15) % 60 + " Phút";
            }
            listTime.add(new SelectItem(i * 15, s));
        }
        return listTime;
    }

    /**
     * @param listTime the listTime to set
     */
    public void setListTime(List<SelectItem> listTime) {
        this.listTime = listTime;
    }

    /**
     * @return the CN307
     */
    public int getCN307() {
        return CN307;
    }

    /**
     * @param CN307 the CN307 to set
     */
    public void setCN307(int CN307) {
        this.CN307 = CN307;
    }

    /**
     * @return the CD301
     */
    public Date getCD301() {
        checkTime();
        return CD301;
    }

    /**
     * @param CD301 the CD301 to set
     */
    public void setCD301(Date CD301) {
        this.CD301 = CD301;
    }

    /**
     * @return the CD302
     */
    public Date getCD302() {
        return CD302;
    }

    /**
     * @param CD302 the CD302 to set
     */
    public void setCD302(Date CD302) {
        this.CD302 = CD302;
    }

    /**
     * @return the CB317
     */
    public String getCB317() {
        return CB317;
    }

    /**
     * @param CB317 the CB317 to set
     */
    public void setCB317(String CB317) {
        this.CB317 = CB317;
    }

    /**
     * @return the CN315
     */
    public int getCN315() {
        return CN315;
    }

    /**
     * @param CN315 the CN315 to set
     */
    public void setCN315(int CN315) {
        this.CN315 = CN315;
    }

    /**
     * @return the PC300
     */
    public int getPC300() {
        return PC300;
    }

    /**
     * @param PC300 the PC300 to set
     */
    public void setPC300(int PC300) {
        this.PC300 = PC300;
    }

    /**
     * @return the FC150
     */
    public String getFC150() {
        return FC150;
    }

    /**
     * @param FC150 the FC150 to set
     */
    public void setFC150(String FC150) {
        this.FC150 = FC150;
    }

    /**
     * @return the pnFC150
     */
    public int getPnFC150() {
        return pnFC150;
    }

    /**
     * @param pnFC150 the pnFC150 to set
     */
    public void setPnFC150(int pnFC150) {
        this.pnFC150 = pnFC150;
    }

    /**
     * @return the FN600
     */
    public int getFN600() {
        return FN600;
    }

    /**
     * @param FN600 the FN600 to set
     */
    public void setFN600(int FN600) {
        this.FN600 = FN600;
    }

    /**
     * @return the FC550
     */
    public String getFC550() {
        return FC550;
    }

    /**
     * @param FC550 the FC550 to set
     */
    public void setFC550(String FC550) {
        this.FC550 = FC550;
    }

    /**
     * @return the FC500
     */
    public int getFC500() {
        return FC500;
    }

    /**
     * @param FC500 the FC500 to set
     */
    public void setFC500(int FC500) {
        this.FC500 = FC500;
    }

    /**
     * @return the FS200
     */
    public int getFS200() {
        return FS200;
    }

    /**
     * @param FS200 the FS200 to set
     */
    public void setFS200(int FS200) {
        this.FS200 = FS200;
    }

    /**
     * @return the CD152
     */
    public Date getCD152() {
        return CD152;
    }

    /**
     * @param CD152 the CD152 to set
     */
    public void setCD152(Date CD152) {
        this.CD152 = CD152;
    }

    /**
     * @return the CD153
     */
    public Date getCD153() {
        return CD153;
    }

    /**
     * @param CD153 the CD153 to set
     */
    public void setCD153(Date CD153) {
        this.CD153 = CD153;
    }

    /**
     * @return the FS250
     */
    public int getFS250() {
        return FS250;
    }

    /**
     * @param FS250 the FS250 to set
     */
    public void setFS250(int FS250) {
        this.FS250 = FS250;
    }

    /**
     * @return the CV165
     */
    public String getCV165() {
        return CV165;
    }

    /**
     * @param CV165 the CV165 to set
     */
    public void setCV165(String CV165) {
        this.CV165 = CV165;
    }

    /**
     * @return the FC450
     */
    public int getFC450() {
        return FC450;
    }

    /**
     * @param FC450 the FC450 to set
     */
    public void setFC450(int FC450) {
        this.FC450 = FC450;
    }

    /**
     * @return the CV151
     */
    public String getCV151() {
        return CV151;
    }

    /**
     * @param CV151 the CV151 to set
     */
    public void setCV151(String CV151) {
        this.CV151 = CV151;
    }

    /**
     * @return the CB173
     */
    public String getCB173() {
        return CB173;
    }

    /**
     * @param CB173 the CB173 to set
     */
    public void setCB173(String CB173) {
        this.CB173 = CB173;
    }

    /**
     * @return the FB050
     */
    public int getFB050() {
        return FB050;
    }

    /**
     * @param FB050 the FB050 to set
     */
    public void setFB050(int FB050) {
        this.FB050 = FB050;
    }

    /**
     * @return the CL196
     */
    public String getCL196() {
        return CL196;
    }

    /**
     * @param CL196 the CL196 to set
     */
    public void setCL196(String CL196) {
        this.CL196 = CL196;
    }

    /**
     * @return the emp_login
     */
    public String getEmp_login() {
        return emp_login;
    }

    /**
     * @param emp_login the emp_login to set
     */
    public void setEmp_login(String emp_login) {
        this.emp_login = emp_login;
    }

    /**
     * @return the nameproject
     */
    public String getNameproject() {
        return nameproject;
    }

    /**
     * @param nameproject the nameproject to set
     */
    public void setNameproject(String nameproject) {
        this.nameproject = nameproject;
    }

    /**
     * @return the c150
     */
    public C150 getC150() {
        return c150;
    }

    /**
     * @param c150 the c150 to set
     */
    public void setC150(C150 c150) {
        this.c150 = c150;
    }

    /**
     * @return the emp
     */
    public String getEmp() {

        return emp;
    }

    /**
     * @param emp the emp to set
     */
    public void setEmp(String emp) {

        this.emp = emp;
    }

    /**
     * @return the messagefrom
     */
    public String getMessagefrom() {
        return messagefrom;
    }

    /**
     * @param messagefrom the messagefrom to set
     */
    public void setMessagefrom(String messagefrom) {
        this.messagefrom = messagefrom;
    }

    /**
     * @return the cd196
     */
    public Date getCd196() {
        return cd196;
    }

    /**
     * @param cd196 the cd196 to set
     */
    public void setCd196(Date cd196) {
        this.cd196 = cd196;
    }

    /**
     * @return the fis
     */
    public int getFis() {
        return fis;
    }

    /**
     * @param fis the fis to set
     */
    public void setFis(int fis) {
        this.fis = fis;
    }
}
